#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

//find；查找指定元素，找到返回指定元素的迭代器，找不到返回结束迭代器end()
//函数原型：find(iterator beg, iterator end, value);// 按值查找元素，找到返回指定位置迭代器，找不到返回结束迭代器位置
//beg 开始迭代器  end 结束迭代器  value 查找的元素

void test1() {
    vector<int> v;
    for (int i = 0; i < 10; ++i) {
        v.push_back(i * i);
    }

    vector<int>::iterator it = find(v.begin(), v.end(), 49);
    if (it == v.end()) {
        cout << "没有找到" << endl;
    } else {
        cout << "找到了" << endl;
    }
}

class Person {
public:
    string name;
    int age;

    Person(string name, int age) {
        this->name = name;
        this->age = age;
    }

    bool operator==(const Person &p) {//重载==
        if (this->name == p.name && this->age == p.age) {
            return true;
        } else {
            return false;
        }
    }
};

void test2() {
    vector<Person> v;
    Person p1("aaa", 10);
    Person p2("bbb", 20);
    Person p3("ccc", 30);
    Person p4("ddd", 40);
    Person p5("eee", 50);

    v.push_back(p1);
    v.push_back(p2);
    v.push_back(p3);
    v.push_back(p4);
    v.push_back(p5);

    vector<Person>::iterator it = find(v.begin(), v.end(), p2);
    if (it == v.end()) {
        cout << "没有找到" << endl;
    } else {
        cout << "找到了" << endl;
    }
}

int main() {
    test1();
    test2();
    return 0;
}